<?php

// start session
session_start();

// connect to database
$conn_str = 'host=dbsrv1.cdf.toronto.edu dbname=csc309g23 user=csc309g23 password=ipheid5h';
$conn = pg_connect($conn_str);

// query database
$query = 'UPDATE rosters SET status=2, team=' . $_POST['team'] . ' WHERE username=\'' . $_POST['username'] . '\' and gameid=' . $_POST['gameid'];


if ($result = pg_query($conn, $query)) { // if succesfully update roster record - i.e accepted invite
    // go back to page from which user logged in
    header('Location: ' . $_SERVER['HTTP_REFERER']);
} else {
  echo $query;
}
?>
